﻿using Mengsk.ProxyDelivery.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mengsk.ProxyDelivery.Service
{
    public class WuliuNumberService : ServiceBase<WuliuNumber>
    {

        private const string APIURL_INSERT = "/webservice/wuliunumber/insert.html";

        public DataCollection<WuliuNumber> GetByAll(string wuliuId, string deliveryCompany, string deliveryNumber, DateTime startTime, DateTime endTime, int pageIndex, int pageSize)
        {
            Request req = new Request { Api = "getByAll" };
            req.Add("wuliuId", wuliuId);
            req.Add("deliveryCompany", deliveryCompany);
            req.Add("deliveryNumber", deliveryNumber);
            req.Add("startTime", startTime);
            req.Add("endTime", endTime);
            req.Add("pageIndex", pageIndex);
            req.Add("pageSize", pageSize);

            return this.DoRemoteCall<WuliuNumber>(req).ToDataCollection();
        }

        public void Save(WuliuNumber wn)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic["wuliuId"] = wn.WuliuId;
            dic["deliveyrCompany"] = wn.DeliveryCompany;
            dic["deliveryNumber"] = wn.DeliveryNumber;
            dic["receiverName"] = wn.ReceiverName;
            dic["receiverPhone"] = wn.ReceiverPhone;
            dic["receiverMobile"] = wn.ReceiverMobile;
            dic["receiverAddress"] = wn.ReceiverAddress;

            var ret = this.DoPost<long>(APIURL_INSERT, dic);
            if (ret.Datas.Count < 1)
            {
                throw new Exception("服务端没有数据返回");
            }
            wn.Id = ret.Datas[0];
        }
    }
}
